Show reviewers ' geographic location
Put the following functions into your functions.php
The principle of implementation is to use Sina and Taobao IP query interface, return IP-owned cityMinor repairs to the code, removed the mount point, directly in the display of comments when calling the function
The code is as follows
Copy Code
/*** Use API to get * @param string $ip* @return string|mixed*/function wpgo_get_city ($ip = null) {$ip = $ip = = null? Wpgo_get_ip ():
, subprocessImport MySQLdbImport re, urllib2Import ConfigParserFrom IPy import IPImport xml. etree. ElementTree as ET Nowtime = time. strftime ('% Y-% m-% d', time. localtime (time. time ()))Configpath = r 'C: portscanconfig. ini'# Input the main path of the api interface, traverse and obtain the list of all ip addresses, and use the IPy module in the format of 127.0.0.1/24Def getiplist (ipinf ):Serverarea = ['tj101 ', 'tj103', 'DH ', 'dx']Iplist = []For area in serverarea:Ipapi = urllib2.urlope
, automatically speculate on the local ISP, update the host, and point the domain name to the correct IP Address
Core code
Rem
///// // Internet isp api detection ///////////////
Set Wgetcmd = 'wget http://int.dpool.sina.com.cn/iplookup/iplookup.php-o-Q'
Echo .> % Logfile %
Echo % Remsep % call Sina ipapi to obtain ISP information % remsep %> % logfile %
For /F "tokens = 2, 3, 4, 5, 6, 7" % A in (% wgetcmd %)
Do (
Set Iparea = %
()))
Configpath=r ' C:portscanconfig.ini '
#传入api接口主路径, traversal gets all the IP listings, formatted as 127.0.0.1/24 with IPY modules
def getiplist (Ipinf):
serverarea=[' tj101 ', ' tj103 ', ' dh ', ' DX '
Iplist=[]
For area in Serverarea:
Ipapi=urllib2.urlopen (Ipinf+area). Read ()
For IP in Ipapi.split (' n '):
#判断如果ip列表不为空, convert to ip/gateway format, then format into IP/24 format
If IP:
Ip=ip.replace (' _ ', '/')
ip= (IP (IP))
Ipl
()))
Configpath=r ' C:portscanconfig.ini '
#传入api接口主路径, traverse get all IP list, format 127.0.0.1/24 with IPY module
def getiplist (Ipinf):
serverarea=[' tj101 ', ' tj103 ', ' dh ', ' DX ']
Iplist=[]
For area in Serverarea:
Ipapi=urllib2.urlopen (Ipinf+area). Read ()
For IP in Ipapi.split (' n '):
#判断如果ip列表不为空, converted to ip/gateway format, and then formatted into IP/24 format
If IP:
Ip=ip.replace (' _ ', '/')
ip= (IP)
Iplist.append (str (IP))
Ips
();
Implementation classes for building interfaces
Ipapi Weatherapi = retrofit.create (Ipapi.class);
Invoke method of interface definition
call
Execute requests asynchronously
Weathercall.enqueue (New callback
@Override
public void Onresponse (call
Ipmodel model = Response.body ();
System.out.println ("Country:" + model.getdata (). Getcountry ());
}
@Override
public void OnFailure (call
System.out.println (T.tostring ());
}
});
7, Advantages:
S
Contact Us
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.